'use strict';
const Service = require('egg').Service;

class CommentsService extends Service {

  async add(params) {
    const { ctx } = this;
    const result = await ctx.model.Comments.create(params);
    return result;
  }

  async lists(params) {
    const { ctx, app } = this;
    const result = await ctx.model.Comments.findAll({
      where: {
        houseId: params.houseId,
      },
      limit: Number(params.pageSize),
      offset: (params.pageNum - 1) * params.pageSize,
      include: [
        {
          model: app.model.Users,
          attributes: [ 'avatar', 'username' ],
        },
      ],
    });
    return result;
  }
}

module.exports = CommentsService;
